import React from 'react'
import { SimpleSelector } from './simpleSelector'
import { AssertTypeProvider } from '../../consts/assertType'

export const AssertTypeSelector = ({ assertTypeCode, onSelectItem, readOnly = false }) => {
    const dataSource = AssertTypeProvider.getAllAssertTypes()
    const filterDataSource = React.useCallback(value => item => item.code.includes(value) || item.title.includes(value), [])
    const getItemValue = React.useCallback(item => item.code, [])
    const renderItem = React.useCallback(item => `${item.code}[${item.title}]`, [])

    return <SimpleSelector dataSource={dataSource} filterDataSource={filterDataSource}
        getItemValue={getItemValue} initValue={assertTypeCode} onSelectItem={onSelectItem}
        readOnly={readOnly} renderItem={renderItem} />
}